package com.sondon.dev_info.servlet_context_listener;

import javax.servlet.ServletContextEvent;

import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.WebApplicationContext;

import com.sondon.dev_soceket.netty.DeviceTCPServer;

/**
 * @Project : Dev_Info_Web
 * @Package : com.sondon.dev_info.servlet_context_listener
 * @Class : MyContextLoaderListener.java
 * @Company 广州讯动网络科技有限公司
 * @Author : 蔡文锋
 * @DateTime：2015年4月24日 上午11:37:55
 * @Blog：http://blog.csdn.net/caiwenfeng_for_23
 * @Description : {}
 */
public class MyContextLoaderListener extends ContextLoaderListener {
	public final static Thread thread=new Thread(new Runnable() {
//		@Override
		public void run() {
			DeviceTCPServer.StartDevSocket();
		}
	});
	
	/**
	 * 
	 */
	public MyContextLoaderListener() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param context
	 */
	public MyContextLoaderListener(WebApplicationContext context) {
		super(context);
		// TODO Auto-generated constructor stub
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.springframework.web.context.ContextLoaderListener#contextInitialized
	 * (javax.servlet.ServletContextEvent)
	 */
	@Override
	public void contextInitialized(ServletContextEvent event) {
		// TODO Auto-generated method stub
		super.contextInitialized(event);
		thread.start();
		
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.springframework.web.context.ContextLoaderListener#contextDestroyed
	 * (javax.servlet.ServletContextEvent)
	 */
	@SuppressWarnings("deprecation")
	@Override
	public void contextDestroyed(ServletContextEvent event) {
		// TODO Auto-generated method stub
		super.contextDestroyed(event);
//		thread.interrupt();
		DeviceTCPServer.StopDevSocket();
		
		thread.stop();
		
	}
}
